package com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.common.utils.base.UuidUtil;
import com.entity.File;
import com.entity.FileRel;
import com.service.base.BaseServiceImp;

@Service("FileService")
public class FileServiceImpl extends BaseServiceImp<File> implements FileService{
	
	@Autowired
	private FileRelService fileRelService;

	@Override
	public String insert(File o) {
		o.setId(UuidUtil.get32UUID());
		o.setFileState(1);
		o.setDownloadTimes(0);
		baseDao.insert(o);
		return o.getId();
	}

	@Override
	public void delete(File o) {
		//批量删除附件关系表 TODO 可以做的更简单
		FileRel rel = new FileRel();
		rel.setFileId(o.getId());
		List<FileRel> rels = fileRelService.find(rel);
		if(rels != null && rels.size() > 0)fileRelService.deleteBatch(rels);
		super.delete(o);
	}
	
	
}
